#ifndef FILESENDER_H
#define FILESENDER_H

#include <QTcpSocket>
#include <QThread>
#include <QHostAddress>
#include <QFileInfo>
#include <QString>

#include "FileKey.h"

class FileSender : public QTcpSocket
{
	Q_OBJECT
	public:
		FileSender();
		~FileSender();
		bool Initialize(QHostAddress addr, int port, QString filePath);
		FileKey GetKey();

	private:
		void SendFile();
		void Stop();
		void SetKey(QHostAddress addr, QString fileName, Mode mode = Tx);

	private slots:
		void Start();
		void ProcessResponse();
		void SocketState(QAbstractSocket::SocketState state);

	signals:
		void sigStarted(FileKey key, long long size);
		void sigError(FileKey key, QString errorStr);
		void sigFileSent(FileKey key, int nbyte);
		void sigComplete(FileKey key);
		void sigTest(FileKey, int nbyte);

	private:
		QHostAddress _addr;
		int _port;
		QThread *_thread;
		QFileInfo _fInfo;
		FILE *_fp;
		FileKey _key;
};

#endif // FILESENDER_H
